import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import vueJsx from "@vitejs/plugin-vue-jsx";

// import { replaceCodePlugin } from "vite-plugin-replace";
// https://vitejs.dev/config/
// @ts-ignore
export default ({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  return defineConfig({
    plugins: [
      vueJsx({}),
      vue(),
      // replaceCodePlugin({
      //   replacements: [
      //     {
      //       from: "onMounted(cacheSubtree);",
      //       // KeepAlive
      //       to: `onMounted(cacheSubtree);
      //       function pruneCacheEntryJustomCustom(key){
      //         const cached = cache.get(key);
      //         if(cached){
      //           pruneCacheEntry(key)
      //         }
      //       }
      //       instance.pruneCacheEntryJustomCustom = pruneCacheEntryJustomCustom;`,
      //     }
      //   ],
      // }),
    ],
    build: {
      target: 'es2015'
    },
    server: {
      proxy: {
        "/api": {
          target: env.VITE_APP_HOST,
          secure: false,
          changeOrigin: true,
        },
        '/auth': {
          target: env.VITE_APP_HOST,
          secure: false,
          changeOrigin: true
        },
        "/uploads": {
          target: env.VITE_APP_HOST,
          secure: false,
          changeOrigin: true,
        },
      },
      host: "0.0.0.0",
      port: 3001
    },
    resolve: {
      dedupe: [
        'vue'
      ],
      alias: {
        "@": resolve(__dirname, "src"),
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@import "./src/styles/variables.scss";@import "./src/styles/public.scss";`,
        },
      },
    },
  });
};
